package com.zretc.blog.controller;

import com.alibaba.fastjson.JSON;
import com.zretc.api.pojo.Comment;
import com.zretc.api.pojo.Reply;
import com.zretc.blog.service.ReplyService;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/blog")
public class ReplyController {
    @Autowired
    ReplyService replyService;
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/addReply")
    public RespResult addReply(@RequestBody Reply reply){
        replyService.addReply(reply);
        return R.success("回复成功");
    }

    @GetMapping("/getReplyByComment")
    public RespResult getReplyByComment(Integer commentId){
    List<Reply> list = replyService.getReplyByComment(commentId);
    return R.success(list);
    }

    @GetMapping("/getReplyByUser")
    public RespResult getReplyByUser(Integer replierId){
        ArrayList<Reply> list = replyService.getReplyByUser(replierId);
        return R.success(list);
    }

    @GetMapping("/deleteReply")
    public  RespResult deleteReply(Integer id){
        replyService.deleteReply(id);
        return R.success("删除回复成功");
    }

    @RequestMapping("/setReplyStatus")
    public RespResult setReplyStatus(Reply reply){
        replyService.setReplyStatus(reply);
        return R.success("审核完成");
    }
    

    @GetMapping("/deleteReplyByComment")
    public  RespResult deleteReplyByComment(Integer commentId){
        replyService.deleteReplyByComment(commentId);
        return R.success("删除回复成功");
    }

    @GetMapping("/likeReply")
    public RespResult likeReply(Integer id){
        replyService.likeReply(id);
        return R.success("点赞回复成功");
    }
    @GetMapping("/getReplyById")
    public  RespResult getReplyById(Integer id){
        Reply reply = replyService.getReplyById(id);
        return R.success(reply);
    }
}
